package net.zjitc.list.web;

import net.zjitc.list.dao.UserDao;
import net.zjitc.list.dao.UserDaoImpl;
import net.zjitc.list.domain.User;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @Author Administrator
 * @Date 2020/6/16 13:48
 * 删除联系人Servlet
 **/
@WebServlet("/delUserServlet")
public class DelUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*
        1、获取请求参数（id）
        2、调用dao方法完成删除用户功能
        3、想要看到删除后最新数据，重定向到userListServlet
        * */
        String ids = request.getParameter("id");
        /* String转int*/
        int id=Integer.parseInt(ids);
        UserDao dao=new UserDaoImpl();
        dao.delete(id);
        /*重定向*/
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/userListServlet");
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
